package com.lagou.homework_1;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class RankBean implements WritableComparable <RankBean> {
    private int rank;
    private int raw_number;

    public RankBean() {
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public int getRaw_number() {
        return raw_number;
    }

    public void setRaw_number(int raw_number) {
        this.raw_number = raw_number;
    }

    public RankBean(int rank, int raw_number){
        this.rank = rank;
        this.raw_number = raw_number;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(this.rank);
        out.writeInt(this.raw_number);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.rank = in.readInt();
        this.raw_number = in.readInt();
    }

    @Override
    public String toString() {
        return rank + " \t" + raw_number;
    }

    @Override
    public int compareTo(RankBean other) {
//        return this.getRaw_number() >= other.getRaw_number()?1:-1;
        int result;
        if(this.getRaw_number()> other.getRaw_number()){
            result  = 1;
        }else if (this.getRaw_number() < other.getRaw_number()){
            result = -1;
        }else {
            result = 0;
        }
        return result;
    }
}
